package com.jht.bletool2kotlin.activity.homepage.fragment.device.bean

import android.bluetooth.BluetoothDevice
import android.os.Parcel
import android.os.Parcelable

data class BLEDevice(val device: BluetoothDevice,var rssi:Int, var scanRecord:ByteArray):Parcelable{
    constructor(parcel: Parcel) : this(
        parcel.readParcelable(BluetoothDevice::class.java.classLoader)!!,
        parcel.readInt(),
        parcel.createByteArray()!!
    ) {
    }

    override fun writeToParcel(parcel: Parcel, flags: Int) {
        parcel.writeParcelable(device, flags)
        parcel.writeInt(rssi)
        parcel.writeByteArray(scanRecord)
    }

    override fun describeContents(): Int {
        return 0
    }

    override fun equals(other: Any?): Boolean {
        if (this === other) return true
        if (javaClass != other?.javaClass) return false

        other as BLEDevice

        if (device != other.device) return false
        if (rssi != other.rssi) return false
        if (!scanRecord.contentEquals(other.scanRecord)) return false

        return true
    }

    override fun hashCode(): Int {
        var result = device.hashCode()
        result = 31 * result + rssi
        result = 31 * result + scanRecord.contentHashCode()
        return result
    }

    companion object CREATOR : Parcelable.Creator<BLEDevice> {
        override fun createFromParcel(parcel: Parcel): BLEDevice {
            return BLEDevice(parcel)
        }

        override fun newArray(size: Int): Array<BLEDevice?> {
            return arrayOfNulls(size)
        }
    }

}
